package cn.zealon.readingcloud.collection.controller;


import cn.zealon.readingcloud.collection.service.BooksService;
import cn.zealon.readingcloud.collection.service.InputToMQSearvice;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@Api(description = "采集调用接口")
@RestController
@RequestMapping("/collect")
public class CollectBooksFromDBController {

    @Autowired
    private BooksService bookService;

    @Autowired
    private InputToMQSearvice inputToES;

    private static Logger log = LoggerFactory.getLogger(CollectBooksFromDBController.class);

    @ApiOperation(value = "发送采集图书请求" , httpMethod = "GET")
    @ApiImplicitParams({})
    @ApiResponses({@ApiResponse(code = 200, message = "")})
    @RequestMapping("/SendCollectBooksFromDB")
    public HashMap<String,Object> sendCollectBook(){
        log.info("发送采集图书请求");
        HashMap<String,Object> msg =  bookService.sendCollectBooks();
        return msg;
    }

    @ApiOperation(value = "接受图书并且存入RabbitMQ" , httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "book", value = "图书", dataType = "Book")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "")})
    @RequestMapping("/inputBooksToES")
    public HashMap<String,Object> inputBooksToES(@RequestBody String bookJson){
        HashMap<String,Object> msg =  inputToES.inputBookToMQ(bookJson);
        return msg;
    }

    @ApiOperation(value = "是否是管理员显示采集图书按钮" , httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "book", value = "图书", dataType = "Book")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "")})
    @RequestMapping("/showCollect")
    public String showCollect(){
//        HashMap<String,Object> msg =  inputToES.inputBookToMQ(bookJson);
        return "false";
    }
}
